package com.xiaopo.flying.stickerview;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Layout;
import android.util.Log;

import com.xiaopo.flying.sticker.Sticker;
import com.xiaopo.flying.sticker.StickerView;
import com.xiaopo.flying.sticker.TextSticker;

/**
 * Created by wuyong on 17/6/23.
 */

public class StickerActivity extends AppCompatActivity {
    private static final String TAG = StickerActivity.class.getSimpleName();
    private StickerView stickerView;
    private TextSticker textSticker;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activiy_sticker);
        
        initSticker();

        setupStickerView();
        
    }

    private void initSticker() {
        textSticker = new TextSticker(this);

        textSticker.setDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.sticker_transparent_background));
        textSticker.setText("Hello, world!");
        textSticker.setTextColor(Color.BLACK);
        textSticker.setTextAlign(Layout.Alignment.ALIGN_CENTER);
        textSticker.resizeText();
    }

    private void setupStickerView() {
        stickerView = (StickerView) findViewById(R.id.sv_sticker);
        stickerView.setLocked(false);
        stickerView.setConstrained(false);
        stickerView.setBackgroundColor(Color.WHITE);
        stickerView.addSticker(textSticker);

        stickerView.setOnStickerOperationListener(new StickerView.OnStickerOperationListener() {
            @Override
            public void onStickerClicked(Sticker sticker) {

            }

            @Override
            public void onStickerDeleted(Sticker sticker) {

            }

            @Override
            public void onStickerDragFinished(Sticker sticker) {
                Log.e(TAG, "onStickerDragFinished: " + sticker.getCurrentInfo());
            }

            @Override
            public void onStickerZoomFinished(Sticker sticker) {
                Log.e(TAG, "onStickerZoomFinished: " + sticker.getCurrentInfo());
            }

            @Override
            public void onStickerFlipped(Sticker sticker) {
                Log.e(TAG, "onStickerFlipped: " + sticker.getCurrentInfo());
            }

            @Override
            public void onStickerDoubleTapped(Sticker sticker) {
                Log.e(TAG, "onStickerDoubleTapped: " + sticker.getCurrentInfo());
            }
        });
    }
}
